let arr = [{
    id: 1,
    name: "",
    children: [{
        id: 2,
        children: [{
            id: 4
        }, {
            id: 5
        }, {
            id: 6
        }]
    }, {
        id: 3,
        children: [{
            id: 7
        }]
    }]
}];

let result = [];
const flatten = function flatten(arr) {
    // 获取这一级数据
    let temp = arr.map(item => item.id);
    result = result.concat(temp);
    // 递归深入查找
    arr.forEach(item => {
        if (item.children) {
            flatten(item.children);
        }
    });
};
flatten(arr);
console.log(result);